package cn.zl.ymcc.result;

import cn.zl.ymcc.exception.errorCode.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private boolean success;
    private String message;
    private T data;
    private String code;
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setMessage("成功");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setMessage("成功");
        return result;
    }
    public static <T> Result<T> error(String message){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setMessage(message);
        return result;
    }
    public static <T> Result<T> error(List  message){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setMessage(message.toString());
        return result;
    }
    public static <T> Result<T> error(String message,String code){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    public static <T> Result<T> error(ErrorCode code){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(code.getCode());
        result.setMessage(code.getMessage());
        return result;
    }
}
